function addSalesRuleWin(ruleGroupId, title) {
	var addSalesRuleGrid = function() {
		var addSalesRuleSm = new Ext.grid.CheckboxSelectionModel();// 创建选择模式对象
		var column = new Ext.grid.ColumnModel({
					columns : [addSalesRuleSm, new Ext.grid.RowNumberer({
										width : 35
									}), {
								dataIndex : "id",
								header : "规则编号",
								sortable : true,
								width : 70
							}, {
								dataIndex : "ruleName",
								header : "规则名称",
								sortable : false,
								width : 100,
								renderer : function(value, meta, record) {
									if (value) {
										meta.attr = 'ext:qtitle="规则名称:" ext:qtip="'
												+ value + '"';
										return value;
									}
								}
							}, {
								dataIndex : "ruleDescribe",
								header : "规则描述",
								sortable : false,
								width : 180,
								renderer : function(value, meta, record) {
									if (value) {
										meta.attr = 'ext:qtitle="规则描述:" ext:qtip="'
												+ value + '"';
										return value;
									}
								}
							}],
					defaults : {
						remoteSort : false,
						menuDisabled : false,
						width : 100
					}
				});

		var addSalesRuleStore = new Ext.data.Store({
					autoLoad : true,// 要加载数据必须设置为true
					proxy : new Ext.data.HttpProxy({
								method : 'POST',
								url : __ctxPath
										+ "/couponRuleManager/querySalesRule"
							}),
					baseParams : {
						start : 0,
						limit : 500
					},
					reader : new Ext.data.JsonReader({
								totalProperty : "totalCount",
								root : "list",
								fields : [{
											name : "id"
										}, {
											name : "ruleName"
										}, {
											name : "ruleDescribe"
										}]

							}),
					listeners : {
						load : function() {
							querySalesRuleById(ruleGroupId);
						}
					}
				});

		var addSalesRulesGrid = new Ext.grid.GridPanel({
					id : 'addSalesRulesGrid',
					anchor : '100% 100%',
					store : addSalesRuleStore,
					stripeRows : true,
					autoScroll : true,
					columnLines : true,
					cm : column,
					sm : addSalesRuleSm,
					loadMask : true,
					loadMask : {
						msg : "正在加载数据，请稍侯……"
					},
					viewConfig : {
						emptyText : '没有您想要的数据'
					}
				});
		return addSalesRulesGrid;
	};

	var addSalesRuleWindow = new Ext.Window({
				id : 'addSalesRuleWindow',
				closeAction : 'destroy',
				title : title,
				closable : true,
				plain : true,
				modal : true,
				// draggable : false, // 不可拖动
				resizable : false, // 不可调整
				width : 500,
				height : 300,
				buttonAlign : 'center',
				autoDestroy : true,
				layout : 'fit',
				items : [addSalesRuleGrid()],
				listeners : {
					'show' : function() {
						// querySalesRuleById(ruleGroupId);
					},
					'beforeshow' : function() {
						addSalesRuleWindow.center();
					}
				},
				buttons : [{
							text : '确定',
							formBind : true,
							handler : function() {
								addSalesRuleConfirm(ruleGroupId);
							}
						}, {
							text : "取消",
							handler : function() {
								addSalesRuleWindow.close();
							}
						}]
			});
	return addSalesRuleWindow;

};

/**
 * 添加规则
 * 
 * @param {}
 *            ruleGroupId
 */
function addSalesRuleConfirm(ruleGroupId) {
	var d = Ext.getCmp("addSalesRulesGrid");
	var jsonrecord = d.getSelectionModel().getSelections();
	if (jsonrecord.length == 0) {
		Ext.MessageBox.show({
					title : "操作信息",
					msg : "请选择要添加的规则!",
					buttons : Ext.MessageBox.OK,
					icon : Ext.MessageBox.WARNING
				});
		return;
	}
	Ext.Msg.confirm("信息确认", "您确定要为该规则组添加所选的规则吗？", function(c) {
				if (c == "yes") {
					var salesRuleIds = "";
					var m = 0;
					for (var i = 0; i < jsonrecord.length; i++) {
						var tmp = jsonrecord[i];
						if (m > 0) {
							salesRuleIds = salesRuleIds + "," + tmp.data.id;
						} else {
							salesRuleIds = tmp.data.id;
						}
						m++;
					}
					commonAddSalesRules(ruleGroupId, salesRuleIds);
				}
			});
}

/**
 * 添加规则到规则组
 * 
 * @param {}
 *            ruleGroupId
 * @param {}
 *            salesRuleIds
 */
function commonAddSalesRules(ruleGroupId, salesRuleIds) {
	var optionMask = new Ext.LoadMask(Ext.getBody(), {
				msg : "正在处理,请稍后..."
			});
	optionMask.show();
	Ext.Ajax.request({
				url : __ctxPath + "/couponRuleManager/updSalesRuleGroup",
				params : {
					ruleGroupId : ruleGroupId,
					salesRuleIds : salesRuleIds
				},
				method : "post",
				success : function(response, config) {
					optionMask.hide();
					var jsonData = Ext.util.JSON.decode(response.responseText);
					if (jsonData.success) {
						Ext.MessageBox.show({
									title : "信息提示",
									msg : jsonData.data,
									buttons : Ext.MessageBox.OK,
									icon : Ext.MessageBox.INFO
								});
						Ext.getCmp("addSalesRuleWindow").close();
					} else {
						Ext.MessageBox.show({
									title : "操作信息",
									msg : jsonData.data,
									buttons : Ext.MessageBox.OK,
									icon : Ext.MessageBox.ERROR
								});
					}
				},
				failure : function(response, config) {
					optionMask.hide();
					Ext.MessageBox.show({
								title : "错误提示",
								msg : "服务器请求异常，请稍后再试!",
								buttons : Ext.MessageBox.OK,
								icon : Ext.MessageBox.ERROR
							});
				}
			});
}

// 初始化该规则组中的规则被选中
function querySalesRuleById(ruleGroupId) {
	Ext.Ajax.request({
				url : __ctxPath + "/couponRuleManager/querySalesRuleGroupById",
				params : {
					ruleGroupId : ruleGroupId
				},
				method : "post",
				success : function(response) {
					var jsonData = Ext.util.JSON.decode(response.responseText);
					var list = jsonData.list;
					var grid = Ext.getCmp("addSalesRulesGrid");
					var selMod = grid.getSelectionModel();
					var salesRuleIds = new Array();
					for (var i = 0; i < list.length; i++) {
						list[i].salesRuleId;
						var index = grid.store.find('id', list[i].salesRuleId);
						salesRuleIds.push(index);
					}
					if (jsonData.success) {
						selMod.selectRows(salesRuleIds);
					} else {
						Ext.MessageBox.show({
									title : "错误提示",
									msg : jsonData.data,
									buttons : Ext.MessageBox.OK,
									icon : Ext.MessageBox.ERROR
								});
					}
				},
				failure : function(response) {
					optionMask.hide();
					Ext.MessageBox.show({
								title : "操作信息",
								msg : "服务器请求异常,请稍后再试!",
								buttons : Ext.MessageBox.OK,
								icon : Ext.MessageBox.ERROR
							});
				}
			});

}
